<?php
namespace app\admin\logic;
use think\Facade\Db;
use app\common\Apiv;
use app\common\Util;
/**
 * @author KEL
 * @Description 
 * @Date   2020-07-10 13:03:41
 * @Author  <1067547248@qq.com>
 */
class LoginLogic{
	static function login(){
		$username = input('username','');
		$password = input('password','');
		$info = Db::name('sys_user')
				->field('id,user_name,password,salt,status,head_img')
				->where('user_name|phone', $username)
				->find();
		if(!$info){
			return Apiv::result(0,1100);
		}
		if($info['status']!=1){
			return Apiv::result(0,1101);
		}
		if($info['password']!=md5(md5($password).$info['salt'])){
			return Apiv::result(0,1102);
		}
		//登录成功
		//生成用户登录token[令牌]并返回给接口
		$token = Util::init()->UUID('user_');
		//token回写数据表
		Db::name('sys_user')->where('id',$info['id'])->update(['token'=>$token]);
		$user = [];
		$user['user_name']  = $info['user_name'];
		$user['status'] 	= $info['status'];
		$user['head_img'] 	= $info['head_img'];
		$user['token'] 		= $token;
		return Apiv::result(1, 0, '登录成功', $user);
	}
}